package com.woniu.admin.util;

import com.woniu.admin.vo.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
public class GlobalExceptionResovler {
    //全局异常处理
    @ExceptionHandler(Exception.class)
    public AjaxResult handler(Exception e) {
        //e.printStackTrace();
        if (e instanceof VerifyCodeException) {
            VerifyCodeException ex = (VerifyCodeException) e;
            return AjaxResult.error(ex.getMessage());

        } else if (e instanceof UserException) {
            UserException ex = (UserException) e;
            return AjaxResult.error(ex.getMessage());

        } else {
            return AjaxResult.error();
        }
    }

}
